package one.bugu.android.demon.ui.activity.shop;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.juefeng.android.framework.LKUtil;
import com.juefeng.android.framework.view.annotation.LKContentView;
import com.juefeng.android.framework.view.annotation.LKInjectView;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import one.bugu.android.demon.R;
import one.bugu.android.demon.bean.BGTInfoBean;
import one.bugu.android.demon.bean.MagicCalDetailBean;
import one.bugu.android.demon.bean.MagicCalShopBean;
import one.bugu.android.demon.common.BaseHttpAsycResponceHandler;
import one.bugu.android.demon.common.MyBaseActivity;
import one.bugu.android.demon.constant.Constant;
import one.bugu.android.demon.constant.HttpConstant;
import one.bugu.android.demon.ui.widget.BaseTopBarView;
import one.bugu.android.demon.util.DateUtils;
import one.bugu.android.demon.util.PreferencesUtil;
import one.bugu.android.demon.util.StatusBarUtils;

/**
 * 钱包详情界面
 */
@SuppressLint("Registered")
@LKContentView(R.layout.activity_order_details)
public class OrderDetailsActivity extends MyBaseActivity {
    /**
     * topBar
     */
    @LKInjectView(R.id.btbv_wd_detail)
    private BaseTopBarView btbv_wd_detail;

    /**
     * 下单状态
     */
    @LKInjectView(R.id.tv_wdt_type)
    private TextView tv_wdt_type;

    /**
     * 下单状态提示
     */
    @LKInjectView(R.id.tv_wdt_name)
    private TextView tv_wdt_name;

    /**
     * 订单状态
     */
    @LKInjectView(R.id.tv_order_status)
    private TextView tv_order_status;

    /**
     * 订单编号
     */
    @LKInjectView(R.id.tv_order_no)
    private TextView tv_order_no;

    /**
     * 订单时间
     */
    @LKInjectView(R.id.tv_order_time)
    private TextView tv_order_time;

    /**
     * 魔法算力值
     */
    @LKInjectView(R.id.tv_order_mgc)
    private TextView tv_order_mgc;

    /**
     * 有效期至
     */
    @LKInjectView(R.id.tv_order_indate)
    private TextView tv_order_indate;

    /**
     * 送bgt
     */
    @LKInjectView(R.id.tv_order_give)
    private TextView tv_order_give;

    /**
     * 首冲
     */
    @LKInjectView(R.id.rl_order_first)
    private RelativeLayout rl_order_first;

    /**
     * 首冲赠送
     */
    @LKInjectView(R.id.tv_order_first_give)
    private TextView tv_order_first_give;

    /**
     * 订单价格
     */
    @LKInjectView(R.id.tv_order_price)
    private TextView tv_order_price;

    private DecimalFormat df = new DecimalFormat("###.#####");

    @Override
    protected void initView() {
        super.initView();
        //设置状态栏
        StatusBarUtils.getInstance().setStatusBar(this, btbv_wd_detail);
    }

    @Override
    protected void initData() {
        super.initData();

        MagicCalDetailBean orderData = (MagicCalDetailBean) getIntent().getSerializableExtra("ORDER_DATA");
        setViewData(orderData);
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        btbv_wd_detail.setEventInterface(new BaseTopBarView.EventInterface() {
            @Override
            public void leftOnClick() {
                finish();
            }

            @Override
            public void leftCloseClick() {

            }

            @Override
            public void rightOnClick() {

            }
        });
    }

    /**
     * 设置界面数据
     *
     * @param data
     */
    @SuppressLint("SetTextI18n")
    private void setViewData(MagicCalDetailBean data) {
        //首冲是否显示
        rl_order_first.setVisibility(data.getFirstGiveBgtNum() > 0 ? View.VISIBLE : View.GONE);
        boolean isSuccess = TextUtils.equals(data.getOrderState(), "20");
        tv_wdt_type.setText(isSuccess ? "下单成功" : "下单失败");
        tv_wdt_name.setText(isSuccess ? "恭喜您下单成功" : TextUtils.isEmpty(data.getFailDesc()) ? "支付异常" : data.getFailDesc());
        tv_order_status.setText(isSuccess ? "成功" : "失败");
        tv_order_no.setText(data.getOrderNo());
        tv_order_time.setText(data.getCreateTime());
        tv_order_mgc.setText("+" + data.getPowerNum());
        tv_order_indate.setText(DateUtils.getBeforeDate(data.getCreateTime(), Integer.parseInt(data.getValidTime())));
        tv_order_give.setText("+" + new DecimalFormat("###").format(data.getGiveBgtNum()));
        tv_order_first_give.setText(new DecimalFormat("###").format(data.getFirstGiveBgtNum()) + "BGT");
        tv_order_price.setText(df.format(data.getOrderMoney()) + "ETH");


    }
}
